// 例子11

(function () {
    var foo = {
        name: 'joker',
        showName: function () {
            console.log(this.name);
        }
    }
    var bar = {
        name: 'rose'
    }
    foo.showName.call(bar); // rose
})();


console.log('----------------------------------');

(function () {
    function exam(a, b, c, d, e) {

        // 先看看函数的自带属性 arguments 什么是样子的
        console.log(arguments); //

        // 使用call/apply将arguments转换为数组,
        // 返回结果为数组，arguments自身不会改变
        var arg = [].slice.call(arguments);

        console.log(arg);
    }

    exam(2, 8, 9, 10, 3);

    // {0:2, 1:8, 2:9, 3:10, 4:3}
    // [2, 8, 9, 10, 3]
})();

console.log('----------------------------------');

(function () {
    // 定义父级的构造函数
    var Person = function (name, age) {
        this.name = name;
        this.age = age;
        this.gender = ['man', 'woman'];
    }

    // 定义子类的构造函数
    var Student = function (name, age, high) {

        // use call
        Person.call(this, name, age);
        this.high = high;
    }
    Student.prototype.message = function () {
        console.log('name:' + this.name + ', age:' + this.age + ', high:' + this.high + ', gender:' + this.gender[0] + ';');
    }

    new Student('xiaom', 12, '150cm').message();

    // result
    // ----------
    // name:xiaom, age:12, high:150cm, gender:man;
})();